package ControlLayer;
import java.util.ArrayList;
import ModelLayer.*;
//model layer package has to be imported
/**
 * Controller class for the DVD collection
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * @revised version English (Ab)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class DVDCtr
{
    //declare instance variables to reference containers
    //passed as arguments from the main class
    private DVDContainer dvdContainer;
    private ArrayList<Copy> copyContainer;

    /**
     * Constructor for objects of class DVDCtr
     */
    public DVDCtr()//DVD container is to be passed as parameter from the main controller
    {
        //set up references to containers  
        dvdContainer=dvdContainer.getDVDContainer();
    }

    //Dummy implementation: more parameters are probaly to added
    public void createDVD(int id, String title, String artist, String releaseDate)//String dvd)
    {       
        //this method constructs a new dvd object 
        //and stores it in the container
        DVD dvd=new DVD(id, title, artist, releaseDate);
        dvdContainer.addDVD(dvd);

    }

    
    //Dummy implementation: after implementing the model layer 
    //objects of class DVD are to be returned, not String
    public DVD findDVD(int id)
    {
        //this method is to search the container for a DVD
        //with an id-number equal to the parameter no
        //when the dvd is found, the method is to call print-methods in the TUI layer
        DVD dvd = dvdContainer.searchDVD(id);

        return dvd; 
    }

    public void updateDVD(int id, String title, String artist, String releaseDate)
    {
        dvdContainer.updateDVD(id, title, artist, releaseDate);
    }

    public void deleteDVD(int id)
    {
        //search for the dvd and delete the object from the container
        dvdContainer.deleteDVD(id);
    }

    public void createCopy(int id, String serialNumber, String purchaseDate, double purchasePrice)
    {
        //create a copy of the specified dvd and add it to the dvd
        DVD dvd=findDVD(id);
        Copy copy=new Copy(serialNumber, purchaseDate, purchasePrice);
        dvd.addCopy(copy);        
    }

    public Copy findCopy(int id, String SerialNumber)
    {
        DVD dvd = findDVD(id);
        Copy copy=dvd.searchCopy(SerialNumber);
        return copy;
    }

    public void updateCopy(int id, String serialNumber, String purchaseDate, double purchasePrice)
    {
        DVD dvd = findDVD(id);
        dvd.updateCopy(serialNumber, purchaseDate, purchasePrice);
    }

    public void deleteCopy(int id, String serialNumber)
    {
        DVD dvd=findDVD(id);
        dvd.deleteCopy(serialNumber);
    }

    public void listAllDvds()
    {
        //returns a list of all dvds and their associated copies
        dvdContainer.listAllDVDs();        
        
    }
}
